#pragma once
#include "CFrameworkElement.h"
#include "CRasterizerEdgeStore.h"
class CImageBrush;
class CEventArgs;
class HitTestPolygon;
class CRectangle;
class CString;


class CMediaBase :
	public CFrameworkElement
{


protected: 
	CMediaBase(CCoreServices * pCore);
protected: 
	virtual ~CMediaBase();
public: 
	virtual XUINT32 GetTypeIndex() const;
	virtual HRESULT EnterImpl(CDependencyObject * pNamescopeOwner, struct EnterParams params);
	virtual HRESULT LeaveImpl(CDependencyObject * pNamescopeOwner, struct LeaveParams params);
	virtual HRESULT UpdateState();
	virtual XFLOAT GetActualWidth();
	virtual XFLOAT GetActualHeight();
	virtual void FireMediaEvent(XUINT32 cEventName, const XUINT16 * pEventName, CEventArgs * * ppArgs);
	virtual CImageBrush * GetBackgroundBrush();
	virtual HRESULT EnsureBrush();
	virtual HRESULT GetBoundingRectangle(struct XRECTF_WH * pRect);
	HRESULT GetVisibleImageSourceBounds(const struct XRECTF_RB * pWindowBounds, struct XRECTF_WH * pBounds);
	struct ICoreMetaSurface * GetCachedSurface();
	static void NWSetMediaSourceDirty(CDependencyObject * pTarget, enum DirtyFlags::Value flags);
	virtual HRESULT PullInheritedTextFormatting();
	virtual XBOOL IsRightToLeft();
	HRESULT UpdateInternalSize(XFLOAT & rActualWidth, XFLOAT & rActualHeight, enum XcpBrushAlignmentX & alignmentX, enum XcpBrushAlignmentY & alignmentY);
protected: 
	virtual XBOOL NWIsContentDirty();
	virtual void NWCleanDirtyFlags();
	virtual HRESULT NWRenderPreChildrenEdgesVirtual(const struct SharedRenderParams & sharedRP, const struct NWRenderParams & nwRP, xvector<xref_ptr<CRasterizerEdgeStore> > & vecEdgeStores);
	virtual XBOOL ShouldPickupParentIsRightToLeft();
	virtual HRESULT EnsureMedia();
	virtual HRESULT EnsureGeometry();
	virtual void CloseMedia();
	virtual HRESULT ComputeScaleFactor(struct XSIZEF * pRenderBounds, struct XSIZEF & scaleFactor, XFLOAT naturalWidth, XFLOAT naturalHeight);
	virtual HRESULT GetNaturalBounds(struct XRECTF_WH & pNaturalBounds);
	virtual HRESULT MeasureOverride(struct XSIZEF availableSize, struct XSIZEF & desiredSize);
	virtual HRESULT ArrangeOverride(struct XSIZEF finalSize, struct XSIZEF & newFinalSize);
	virtual XBOOL HasValidMediaSource();
	virtual XBOOL ShouldCreateBackgroundBrush();
	virtual HRESULT GenerateContentBounds(struct XRECTF_RB * pBounds);
	virtual HRESULT HitTestLocalInternal(const HitTestPolygon & target, XBOOL * pHit);
	virtual HRESULT HitTestLocalInternal(const struct XPOINTF & target, XBOOL * pHit);
	HRESULT MeasureArrangeHelper(struct XSIZEF availableSize, struct XSIZEF & desiredSize);
private: 
	HRESULT RegisterForUpdate();
private: 
	HRESULT UnregisterForUpdate();
public: 
	CString * m_pSource;
public: 
	enum XcpBrushStretch m_Stretch;
protected: 
	CImageBrush * m_pBackgroundBrush;
private: 
	CRectangle * m_pBackgroundRect;
	XFLOAT m_eActualWidth;
	XFLOAT m_eActualHeight;
	struct IPALSurface * m_pOWInternalCompositionTexture;
	struct ICoreMetaSurface * m_pCachedMediaSurface;
	struct  
	{
		XBOOL m_fRegisteredForUpdate:1;
		XBOOL m_fSizeChanged:1;
		XBOOL m_mediaSourceDirty:1;
	};

protected: 
	virtual HRESULT D2DComputeInnerBounds(struct XRECTF_RB * pInnerBounds);
	virtual HRESULT D2DEnsureResources(const struct D2DPrecomputeParams & cp, const CMILMatrix * pMyAccumulatedTransform);
	virtual HRESULT D2DPreChildrenRenderVirtual(const struct SharedRenderParams & sharedRP, const struct D2DRenderParams & d2dRP);
	virtual HRESULT D2DHitTestSelf(struct XPOINTF ptHit, CUIElement * * ppResult);
	virtual HRESULT PreChildrenPrintVirtual(const struct SharedRenderParams & sharedPrintParams, const struct D2DPrecomputeParams & cp, const struct D2DRenderParams & printParams);
};

